package com.ywl.designpattern.prototype.deepclone;

import java.util.HashMap;
import java.util.Map;

public class CarCache {
    private static Map<String, Car> carMap = new HashMap<>();

    public static Car getCar(String carId) {
        Car cachedCar = carMap.get(carId);
        return cachedCar.clone();
    }

    public static void loadCache() {
        Car tesla = new Car("Tesla", new Engine("Electric"));
        carMap.put("1", tesla);

        Car toyota = new Car("Toyota", new Engine("Hybrid"));
        carMap.put("2", toyota);
    }
}

